<template>
    <div id="index" ref="appRef">
      <div class="bg">
        <dv-loading v-if="loading">Loading...</dv-loading>
        <div v-else class="host-body">
          <div class="d-flex jc-center">
            <dv-decoration-10 class="dv-dec-10" />
            <div class="d-flex jc-center">
              <dv-decoration-8 class="dv-dec-8" :color="decorationColors" />
              <div class="title">
                <span class="title-text">汾阳专科护理操作眼科</span>
                <dv-decoration-6
                  class="dv-dec-6"
                  :reverse="true"
                  :color="['#50e3c2', '#67a1e5']"
                />
              </div>
              <dv-decoration-8
                class="dv-dec-8"
                :reverse="true"
                :color="decorationColors"
              />
            </div>
            <dv-decoration-10 class="dv-dec-10-s" />
          </div>
  
          <!-- 第二行 -->
          <div class="d-flex jc-between px-2">
            <div class="d-flex aside-width">
              <div class="react-left ml-4 react-l-s">
                <span class="react-before"></span>
                <span class="text" @click="goToHomePage">返回首页</span>
                <span class="text" @click="goToPuJiangWardPage">浦江</span>
              </div>
              <div class="react-left ml-3" style=" width:260px;">
                <span class="text">{{ subtitle[1] }}</span>
              </div>
            </div>
            <div class="d-flex aside-width">
              <div class="react-right mr-3" style="background-color: #0f1325;width:250px;" > 
                <span class="text fw-b">{{ subtitle[2]}}</span>
              </div>
              <div class="react-right mr-4 react-l-s">
                <span class="react-after"></span>
                <span class="text">
                  {{ timeInfo.dateYear }} {{ timeInfo.dateWeek }}
                  {{ timeInfo.dateDay }}
                </span>
              </div>
            </div>
          </div>
          <div class="body-box">
              <div class="WardBox">
                  <WardView  v-for="index in 18"
                  :key="index"
                  :title="getChineseNumber(index)"
                  />
            </div>
          </div>
        </div>
      </div>
    </div>
  </template>
    
  <script lang="ts">
  import { defineComponent, ref, reactive, onMounted, onUnmounted } from "vue";
  import { formatTime } from "@/utils/index";
  import { WEEK } from "@/constant/index";
  import useDraw from "@/utils/useDraw";
  import { title, subtitle, moduleInfo } from "@/constant/index";
  import { RouterLink, RouterView } from "vue-router";
  import WardView from "./WardView.vue";
  export default defineComponent({
    components: {
    WardView
    },
    setup() {
      // * 颜色
      const decorationColors = ["#568aea", "#000000"];
      // * 加载标识
      const loading = ref<boolean>(true);
      // * 时间内容
      const timeInfo = reactive({
        setInterval: 0,
        dateDay: "",
        dateYear: "",
        dateWeek: "",
      });
      // * 适配处理
      const { appRef, calcRate, windowDraw, unWindowDraw } = useDraw();
      // 生命周期
      onMounted(() => {
        cancelLoading();
        handleTime();
        // todo 屏幕适应
        windowDraw();
        calcRate();
      });
  
      onUnmounted(() => {
        unWindowDraw();
        clearInterval(timeInfo.setInterval);
      });
  
      // methods
      // todo 处理 loading 展示
      const cancelLoading = () => {
        setTimeout(() => {
          loading.value = false;
        }, 500);
      };
  
      // todo 处理时间监听
      const handleTime = () => {
        timeInfo.setInterval = setInterval(() => {
          const date = new Date();
          timeInfo.dateDay = formatTime(date, "HH: mm: ss");
          timeInfo.dateYear = formatTime(date, "yyyy-MM-dd");
          timeInfo.dateWeek = WEEK[date.getDay()];
        }, 1000);
      };
  
       const getChineseNumber = (num: number) => {
        let result = '';
        switch (num) {
          case 1:
            result = '护理部';
            break;
             case 2:
            result = '一病区';
            break;
             case 3:
            result = '二病区';
            break;
             case 4:
            result = '三病区';
            break;
             case 5:
            result = '四病区';
            break;
             case 6:
            result = '特需病区';
            break;
             case 7:
            result = '八病区';
            break;
             case 8:
            result = '术后观察室';
            break;
              case 9:
            result = '急诊室';
            break;
            case 10:
            result = '眼门诊';
            break;
            case 11:
            result = '耳门诊';
            break;
            case 12:
            result = '特需门诊';
            break;
            case 13:
            result = '手术室';
            break;
            case 14:
            result = '供应室';
            break;
            case 15:
            result = '视光学';
            break;
            case 16:
            result = '临床科研助理';
            break;
            case 17:
            result = '十七病区';
            break;
            case 18:
            result = '急诊室';
            break;
            default:
            result='';
            break;
        }
        return result;
      };
  
      return {
        loading,
        timeInfo,
        appRef,
        title,
        subtitle,
        moduleInfo,
        getChineseNumber,
      };
    },
    methods: {
      goToHomePage() {
        this.$router.push({ name: "Index" });
      },
      goToPuJiangWardPage()
      {
        this.$router.push({ name: "PuJiangZKHLYK" });
      },
    },
  });
  </script>
    
    <style lang="scss" scoped>
  @import "../FenYangZKHLYKView/ZKHLK.scss";
  </style>
    